import numpy as np
import torch


per = np.random.permutation(range(8))
print(per)

cho = np.random.choice(range(8))
print(cho)

from torch.utils.data import Dataset, SubsetRandomSampler

class MyCustomDataset(Dataset):
    def __init__(self, data):
        self.data = data

    def __len__(self):
        return len(self.data)

    def __getitem__(self, idx):
        return self.data[idx]

# 假设我们有一些数据
data = [i for i in range(100)]  # 100个数据点
dataset = MyCustomDataset(data)

# 指定随机采样的索引，这里随机采样10个不同的数据点
indices = torch.randperm(len(dataset))[:10]
sampler = SubsetRandomSampler(indices)

from torch.utils.data import DataLoader

sample_size = len(dataset)
sampler1 = torch.utils.data.sampler.SubsetRandomSampler(
    np.random.choice(range(len(dataset)), sample_size))

data_loader = DataLoader(dataset, batch_size=2, sampler=sampler1)
for data in data_loader:
    # 这里执行你的训练逻辑
    print(data)



